<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryForm" size="small" :inline="true" v-show="showSearch" label-width="68px">
      <el-form-item label="序号" prop="orderSn">
        <el-input
          v-model="queryParams.orderSn"
          placeholder="请输入序号"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="用户姓名" prop="name">
        <el-input
          v-model="queryParams.name"
          placeholder="请输入用户姓名"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="生日" prop="birthday">
        <el-date-picker clearable
          v-model="queryParams.birthday"
          type="date"
          value-format="yyyy-MM-dd"
          placeholder="请选择生日">
        </el-date-picker>
      </el-form-item>
      <el-form-item label="年龄" prop="age">
        <el-input
          v-model="queryParams.age"
          placeholder="请输入年龄"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="身高" prop="height">
        <el-input
          v-model="queryParams.height"
          placeholder="请输入身高"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="体重" prop="weight">
        <el-input
          v-model="queryParams.weight"
          placeholder="请输入体重"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="BMI" prop="bmi">
        <el-input
          v-model="queryParams.bmi"
          placeholder="请输入BMI"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="T值" prop="t">
        <el-input
          v-model="queryParams.t"
          placeholder="请输入T值"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="Z值" prop="z">
        <el-input
          v-model="queryParams.z"
          placeholder="请输入Z值"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="BMD" prop="bmd">
        <el-input
          v-model="queryParams.bmd"
          placeholder="请输入BMD"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="创建时间" prop="time">
        <el-input
          v-model="queryParams.time"
          placeholder="请输入创建时间"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="日期" prop="date">
        <el-date-picker clearable
          v-model="queryParams.date"
          type="date"
          value-format="yyyy-MM-dd"
          placeholder="请选择日期">
        </el-date-picker>
      </el-form-item>
      <el-form-item label="身份证" prop="idCard">
        <el-input
          v-model="queryParams.idCard"
          placeholder="请输入身份证"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="骨峰值" prop="bmdMax">
        <el-input
          v-model="queryParams.bmdMax"
          placeholder="请输入骨峰值"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="骨密度年龄值" prop="bmdAge">
        <el-input
          v-model="queryParams.bmdAge"
          placeholder="请输入骨密度年龄值"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="影像诊断" prop="dcmDiagnosis">
        <el-input
          v-model="queryParams.dcmDiagnosis"
          placeholder="请输入影像诊断"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="电话" prop="tel">
        <el-input
          v-model="queryParams.tel"
          placeholder="请输入电话"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="部位" prop="position">
        <el-input
          v-model="queryParams.position"
          placeholder="请输入部位"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="侧别" prop="side">
        <el-input
          v-model="queryParams.side"
          placeholder="请输入侧别"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="送诊科室" prop="referralDepartment">
        <el-input
          v-model="queryParams.referralDepartment"
          placeholder="请输入送诊科室"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="临床诊断" prop="clinicalDiagnosis">
        <el-input
          v-model="queryParams.clinicalDiagnosis"
          placeholder="请输入临床诊断"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="送检医生" prop="submittingDoctor">
        <el-input
          v-model="queryParams.submittingDoctor"
          placeholder="请输入送检医生"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="检查医生" prop="inspectDoctor">
        <el-input
          v-model="queryParams.inspectDoctor"
          placeholder="请输入检查医生"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="审核医生" prop="reviewDoctor">
        <el-input
          v-model="queryParams.reviewDoctor"
          placeholder="请输入审核医生"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="报告日期">
        <el-date-picker
          v-model="daterangeReportDate"
          style="width: 240px"
          value-format="yyyy-MM-dd"
          type="daterange"
          range-separator="-"
          start-placeholder="开始日期"
          end-placeholder="结束日期"
        ></el-date-picker>
      </el-form-item>
      <el-form-item label="医院" prop="hospital">
        <el-input
          v-model="queryParams.hospital"
          placeholder="请输入医院"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="医院地址" prop="hospitalAddr">
        <el-input
          v-model="queryParams.hospitalAddr"
          placeholder="请输入医院地址"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="用户地址" prop="userAddr">
        <el-input
          v-model="queryParams.userAddr"
          placeholder="请输入用户地址"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="建议" prop="suggest">
        <el-input
          v-model="queryParams.suggest"
          placeholder="请输入建议"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="用户id" prop="userId">
        <el-input
          v-model="queryParams.userId"
          placeholder="请输入用户id"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>

    <el-row :gutter="10" class="mb8">
      <el-col :span="1.5">
        <el-button
          type="primary"
          plain
          icon="el-icon-plus"
          size="mini"
          @click="handleAdd"
          v-hasPermi="['ray:checklist:add']"
        >新增</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="success"
          plain
          icon="el-icon-edit"
          size="mini"
          :disabled="single"
          @click="handleUpdate"
          v-hasPermi="['ray:checklist:edit']"
        >修改</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="danger"
          plain
          icon="el-icon-delete"
          size="mini"
          :disabled="multiple"
          @click="handleDelete"
          v-hasPermi="['ray:checklist:remove']"
        >删除</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="warning"
          plain
          icon="el-icon-download"
          size="mini"
          @click="handleExport"
          v-hasPermi="['ray:checklist:export']"
        >导出</el-button>
      </el-col>
      <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
    </el-row>

    <el-table v-loading="loading" :data="checklistList" @selection-change="handleSelectionChange">
      <el-table-column type="selection" width="55" align="center" />
      <el-table-column label="${comment}" align="center" prop="id" />
      <el-table-column label="序号" align="center" prop="orderSn" />
      <el-table-column label="用户姓名" align="center" prop="name" />
      <el-table-column label="性别" align="center" prop="sex" />
      <el-table-column label="生日" align="center" prop="birthday" width="180">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.birthday, '{y}-{m}-{d}') }}</span>
        </template>
      </el-table-column>
      <el-table-column label="年龄" align="center" prop="age" />
      <el-table-column label="身高" align="center" prop="height" />
      <el-table-column label="体重" align="center" prop="weight" />
      <el-table-column label="BMI" align="center" prop="bmi" />
      <el-table-column label="T值" align="center" prop="t" />
      <el-table-column label="Z值" align="center" prop="z" />
      <el-table-column label="BMD" align="center" prop="bmd" />
      <el-table-column label="创建时间" align="center" prop="time" />
      <el-table-column label="日期" align="center" prop="date" width="180">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.date, '{y}-{m}-{d}') }}</span>
        </template>
      </el-table-column>
      <el-table-column label="身份证" align="center" prop="idCard" />
      <el-table-column label="骨峰值" align="center" prop="bmdMax" />
      <el-table-column label="骨密度年龄值" align="center" prop="bmdAge" />
      <el-table-column label="影像诊断" align="center" prop="dcmDiagnosis" />
      <el-table-column label="电话" align="center" prop="tel" />
      <el-table-column label="部位" align="center" prop="position" />
      <el-table-column label="侧别" align="center" prop="side" />
      <el-table-column label="送诊科室" align="center" prop="referralDepartment" />
      <el-table-column label="临床诊断" align="center" prop="clinicalDiagnosis" />
      <el-table-column label="送检医生" align="center" prop="submittingDoctor" />
      <el-table-column label="检查医生" align="center" prop="inspectDoctor" />
      <el-table-column label="审核医生" align="center" prop="reviewDoctor" />
      <el-table-column label="报告日期" align="center" prop="reportDate" width="180">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.reportDate, '{y}-{m}-{d}') }}</span>
        </template>
      </el-table-column>
      <el-table-column label="医院" align="center" prop="hospital" />
      <el-table-column label="医院地址" align="center" prop="hospitalAddr" />
      <el-table-column label="用户地址" align="center" prop="userAddr" />
      <el-table-column label="建议" align="center" prop="suggest" />
      <el-table-column label="图像文件" align="center" prop="imageFile" />
      <el-table-column label="用户id" align="center" prop="userId" />
      <el-table-column label="操作" align="center" class-name="small-padding fixed-width">
        <template slot-scope="scope">
          <el-button
            size="mini"
            type="text"
            icon="el-icon-edit"
            @click="handleUpdate(scope.row)"
            v-hasPermi="['ray:checklist:edit']"
          >修改</el-button>
          <el-button
            size="mini"
            type="text"
            icon="el-icon-delete"
            @click="handleDelete(scope.row)"
            v-hasPermi="['ray:checklist:remove']"
          >删除</el-button>
        </template>
      </el-table-column>
    </el-table>
    
    <pagination
      v-show="total>0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />

    <!-- 添加或修改骨密度检查对话框 -->
    <el-dialog :title="title" :visible.sync="open" width="500px" append-to-body>
      <el-form ref="form" :model="form" :rules="rules" label-width="80px">
        <el-form-item label="序号" prop="orderSn">
          <el-input v-model="form.orderSn" placeholder="请输入序号" />
        </el-form-item>
        <el-form-item label="用户姓名" prop="name">
          <el-input v-model="form.name" placeholder="请输入用户姓名" />
        </el-form-item>
        <el-form-item label="生日" prop="birthday">
          <el-date-picker clearable
            v-model="form.birthday"
            type="date"
            value-format="yyyy-MM-dd"
            placeholder="请选择生日">
          </el-date-picker>
        </el-form-item>
        <el-form-item label="年龄" prop="age">
          <el-input v-model="form.age" placeholder="请输入年龄" />
        </el-form-item>
        <el-form-item label="身高" prop="height">
          <el-input v-model="form.height" placeholder="请输入身高" />
        </el-form-item>
        <el-form-item label="体重" prop="weight">
          <el-input v-model="form.weight" placeholder="请输入体重" />
        </el-form-item>
        <el-form-item label="BMI" prop="bmi">
          <el-input v-model="form.bmi" placeholder="请输入BMI" />
        </el-form-item>
        <el-form-item label="T值" prop="t">
          <el-input v-model="form.t" placeholder="请输入T值" />
        </el-form-item>
        <el-form-item label="Z值" prop="z">
          <el-input v-model="form.z" placeholder="请输入Z值" />
        </el-form-item>
        <el-form-item label="BMD" prop="bmd">
          <el-input v-model="form.bmd" placeholder="请输入BMD" />
        </el-form-item>
        <el-form-item label="创建时间" prop="time">
          <el-input v-model="form.time" placeholder="请输入创建时间" />
        </el-form-item>
        <el-form-item label="日期" prop="date">
          <el-date-picker clearable
            v-model="form.date"
            type="date"
            value-format="yyyy-MM-dd"
            placeholder="请选择日期">
          </el-date-picker>
        </el-form-item>
        <el-form-item label="身份证" prop="idCard">
          <el-input v-model="form.idCard" placeholder="请输入身份证" />
        </el-form-item>
        <el-form-item label="骨峰值" prop="bmdMax">
          <el-input v-model="form.bmdMax" placeholder="请输入骨峰值" />
        </el-form-item>
        <el-form-item label="骨密度年龄值" prop="bmdAge">
          <el-input v-model="form.bmdAge" placeholder="请输入骨密度年龄值" />
        </el-form-item>
        <el-form-item label="影像诊断" prop="dcmDiagnosis">
          <el-input v-model="form.dcmDiagnosis" placeholder="请输入影像诊断" />
        </el-form-item>
        <el-form-item label="电话" prop="tel">
          <el-input v-model="form.tel" placeholder="请输入电话" />
        </el-form-item>
        <el-form-item label="部位" prop="position">
          <el-input v-model="form.position" placeholder="请输入部位" />
        </el-form-item>
        <el-form-item label="侧别" prop="side">
          <el-input v-model="form.side" placeholder="请输入侧别" />
        </el-form-item>
        <el-form-item label="送诊科室" prop="referralDepartment">
          <el-input v-model="form.referralDepartment" placeholder="请输入送诊科室" />
        </el-form-item>
        <el-form-item label="临床诊断" prop="clinicalDiagnosis">
          <el-input v-model="form.clinicalDiagnosis" placeholder="请输入临床诊断" />
        </el-form-item>
        <el-form-item label="送检医生" prop="submittingDoctor">
          <el-input v-model="form.submittingDoctor" placeholder="请输入送检医生" />
        </el-form-item>
        <el-form-item label="检查医生" prop="inspectDoctor">
          <el-input v-model="form.inspectDoctor" placeholder="请输入检查医生" />
        </el-form-item>
        <el-form-item label="审核医生" prop="reviewDoctor">
          <el-input v-model="form.reviewDoctor" placeholder="请输入审核医生" />
        </el-form-item>
        <el-form-item label="报告日期" prop="reportDate">
          <el-date-picker clearable
            v-model="form.reportDate"
            type="date"
            value-format="yyyy-MM-dd"
            placeholder="请选择报告日期">
          </el-date-picker>
        </el-form-item>
        <el-form-item label="医院" prop="hospital">
          <el-input v-model="form.hospital" placeholder="请输入医院" />
        </el-form-item>
        <el-form-item label="医院地址" prop="hospitalAddr">
          <el-input v-model="form.hospitalAddr" placeholder="请输入医院地址" />
        </el-form-item>
        <el-form-item label="用户地址" prop="userAddr">
          <el-input v-model="form.userAddr" placeholder="请输入用户地址" />
        </el-form-item>
        <el-form-item label="建议" prop="suggest">
          <el-input v-model="form.suggest" placeholder="请输入建议" />
        </el-form-item>
        <el-form-item label="图像文件" prop="imageFile">
          <file-upload v-model="form.imageFile"/>
        </el-form-item>
        <el-form-item label="用户id" prop="userId">
          <el-input v-model="form.userId" placeholder="请输入用户id" />
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitForm">确 定</el-button>
        <el-button @click="cancel">取 消</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
import { listChecklist, getChecklist, delChecklist, addChecklist, updateChecklist } from "@/api/ray/checklist";

export default {
  name: "Checklist",
  data() {
    return {
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 骨密度检查表格数据
      checklistList: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 用户id时间范围
      daterangeReportDate: [],
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        orderSn: null,
        name: null,
        sex: null,
        birthday: null,
        age: null,
        height: null,
        weight: null,
        bmi: null,
        t: null,
        z: null,
        bmd: null,
        time: null,
        date: null,
        idCard: null,
        bmdMax: null,
        bmdAge: null,
        dcmDiagnosis: null,
        tel: null,
        position: null,
        side: null,
        referralDepartment: null,
        clinicalDiagnosis: null,
        submittingDoctor: null,
        inspectDoctor: null,
        reviewDoctor: null,
        reportDate: null,
        hospital: null,
        hospitalAddr: null,
        userAddr: null,
        suggest: null,
        imageFile: null,
        userId: null
      },
      // 表单参数
      form: {},
      // 表单校验
      rules: {
        userId: [
          { required: true, message: "用户id不能为空", trigger: "blur" }
        ]
      }
    };
  },
  created() {
    this.getList();
  },
  methods: {
    /** 查询骨密度检查列表 */
    getList() {
      this.loading = true;
      this.queryParams.params = {};
      if (null != this.daterangeReportDate && '' != this.daterangeReportDate) {
        this.queryParams.params["beginReportDate"] = this.daterangeReportDate[0];
        this.queryParams.params["endReportDate"] = this.daterangeReportDate[1];
      }
      listChecklist(this.queryParams).then(response => {
        this.checklistList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },
    // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
    },
    // 表单重置
    reset() {
      this.form = {
        id: null,
        orderSn: null,
        name: null,
        sex: null,
        birthday: null,
        age: null,
        height: null,
        weight: null,
        bmi: null,
        t: null,
        z: null,
        bmd: null,
        time: null,
        date: null,
        idCard: null,
        bmdMax: null,
        bmdAge: null,
        dcmDiagnosis: null,
        tel: null,
        position: null,
        side: null,
        referralDepartment: null,
        clinicalDiagnosis: null,
        submittingDoctor: null,
        inspectDoctor: null,
        reviewDoctor: null,
        reportDate: null,
        hospital: null,
        hospitalAddr: null,
        userAddr: null,
        suggest: null,
        imageFile: null,
        userId: null
      };
      this.resetForm("form");
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.daterangeReportDate = [];
      this.resetForm("queryForm");
      this.handleQuery();
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map(item => item.id)
      this.single = selection.length!==1
      this.multiple = !selection.length
    },
    /** 新增按钮操作 */
    handleAdd() {
      this.reset();
      this.open = true;
      this.title = "添加骨密度检查";
    },
    /** 修改按钮操作 */
    handleUpdate(row) {
      this.reset();
      const id = row.id || this.ids
      getChecklist(id).then(response => {
        this.form = response.data;
        this.open = true;
        this.title = "修改骨密度检查";
      });
    },
    /** 提交按钮 */
    submitForm() {
      this.$refs["form"].validate(valid => {
        if (valid) {
          if (this.form.id != null) {
            updateChecklist(this.form).then(response => {
              this.$modal.msgSuccess("修改成功");
              this.open = false;
              this.getList();
            });
          } else {
            addChecklist(this.form).then(response => {
              this.$modal.msgSuccess("新增成功");
              this.open = false;
              this.getList();
            });
          }
        }
      });
    },
    /** 删除按钮操作 */
    handleDelete(row) {
      const ids = row.id || this.ids;
      this.$modal.confirm('是否确认删除骨密度检查编号为"' + ids + '"的数据项？').then(function() {
        return delChecklist(ids);
      }).then(() => {
        this.getList();
        this.$modal.msgSuccess("删除成功");
      }).catch(() => {});
    },
    /** 导出按钮操作 */
    handleExport() {
      this.download('ray/checklist/export', {
        ...this.queryParams
      }, `checklist_${new Date().getTime()}.xlsx`)
    }
  }
};
</script>
